﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Gnosis.Alexandria.Data;

namespace Gnosis.Alexandria.Views
{
    public partial class NavigateView : WorkView
    {
        public NavigateView()
        {
            InitializeComponent();
        }

        private void txtSearch_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13 && !string.IsNullOrEmpty(txtSearch.Text))
            {
                e.Handled = true;
                var search = txtSearch.Text;
                var searchRequestData = new SearchRequestData { Source = this.Name, Search = search };
                var message = new Message(MessageTypes.RequestNavigateViewSearch, searchRequestData);
                HandleMessage(message);
                Controller.Send(this, message);
            }
        }

        protected void SetSearchText(string search)
        {
            txtSearch.Text = search ?? string.Empty;
        }

        protected override void HandleMessage(IMessageOld message)
        {
            switch (message.Type)
            {
                case MessageTypes.ResponseMainTabViewTabSelected:
                {
                    var control = txtSearch as Control;
                    if (control != null)
                        control.Select();
                    break;
                }
                default:
                    base.HandleMessage(message);
                    break;
            }
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            HandleMessage(new Message(MessageTypes.RequestNavigateViewBack));
        }

        private void btnForward_Click(object sender, EventArgs e)
        {
            HandleMessage(new Message(MessageTypes.RequestNavigateViewForward));
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            HandleMessage(new Message(MessageTypes.RequestNavigateViewRefresh));
        }
    }
}
